STEP 13: Our while loop is now set up, but how do we know if a line of code causes an error?
A try-except block protects the program from crashing if the code underneath the try fails. If the code indented underneath the try prompts an error, then the code underneath the except runs.
- In , drag Try Generic Exception into handle_user_errors() inside your while loop.
- Click Run and Console. Dividing by zero causes an error, so the print command ran instead!
To navigate the page using the TAB key, first press ESC to exit the code editor.